package com.prototype.view {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Matrix;
	import flash.geom.Point;
	/**
	 * ...
	 * @author Santiago.J.Elizalde
	 */
	public class BGRenderer {
		
		public var display:Bitmap;
		
		public var buffer:BitmapData;
		private var screenBuffer:BitmapData;
		private var xScroll:int;
		
		public function BGRenderer() {
			
			buffer = new BitmapData(864, 600-Main.FLOOR_HEIGHT+50);
			var vBar:BitmapData = new BitmapData(32,  Main.FLOOR_HEIGHT + 200, false);
			var yPos:int = 0;
			var tile:BitmapData = new BitmapData(32, 100, false);
			var transform:Matrix = new Matrix();
			//transform.scale(0.1, 0.1);
			tile.draw(new BMPGrassTile(), transform, null, null, null, true);
			
			while (yPos < vBar.height) {
				vBar.copyPixels(tile, tile.rect, new Point(0, yPos), null, null, false);
				yPos += tile.height;
			}
			
			var xPos:int = 0;
			while (xPos < buffer.width) {
				buffer.copyPixels(vBar, vBar.rect, new Point(xPos, 0), null, null, false);
				xPos += vBar.width;
			}
			screenBuffer = new BitmapData(buffer.width, buffer.height, false);
			display = new Bitmap(screenBuffer);
		}
		
		public function scroll():void {
			var transform:Matrix = new Matrix();
			transform.translate(xScroll, 0);
			xScroll -= 4;
			if (xScroll <= -32) {
				xScroll = 0;
			}
			screenBuffer.draw(buffer, transform);
		}
	}

}